<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2874：训练士兵</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">训练士兵</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">训练士兵</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                训练士兵                </h1>
                <p>时间限制：30s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：512MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><p class="MsoNormal" align="center" style="text-align:center"><font face="宋体" size="5"><br />
</font></p>
<p class="MsoNormal" style="text-indent:21.0pt"><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">Ryz</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">正在着手于训练一批精锐士兵。</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:21.0pt"><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">Ryz</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">手下有</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">n*m</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">个士兵，排成一个</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">n</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">行</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">m</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">列的方阵。在一天中，</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">ryz</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">会对士兵下达一些命令，每个命令作用于一个小方阵的所有士兵，并且会增加他们的疲劳值。现在</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt">ryz</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;">想知道，在一整天训练中，某些小方阵中的士兵的疲劳值总和是多少。</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:
10.0pt"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><font face="宋体" size="3"><br />
</font></p>
<p></p></p><hr/><h3>输入格式</h3><p><p></p>
<div></div>
<div>
<p class="MsoNormal" style="text-indent: 21pt; "><span style="font-size: 12pt; font-family: 宋体; ">第一行有</span><span lang="EN-US" style="font-size: 12pt; ">3</span><span style="font-size: 12pt; font-family: 宋体; ">个整数</span><span lang="EN-US" style="font-size: 12pt; ">n,m,k,q</span><span style="font-size: 12pt; font-family: 宋体; ">。分别表示方阵的行数、列数、指令数和询问数。</span><span lang="EN-US" style="font-size: 12pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span style="font-size: 12pt; font-family: 宋体; ">接下来</span><span lang="EN-US" style="font-size: 12pt; ">k</span><span style="font-size: 12pt; font-family: 宋体; ">行，每行</span><span lang="EN-US" style="font-size: 12pt; ">5</span><span style="font-size: 12pt; font-family: 宋体; ">个整数</span><span lang="EN-US" style="font-size: 12pt; ">x1,x2,y1,y2,s</span><span style="font-size: 12pt; font-family: 宋体; ">，描述一个指令，表示这条指令对所有坐标</span><span lang="EN-US" style="font-size: 12pt; ">(x,y)</span><span style="font-size: 12pt; font-family: 宋体; ">满足</span><span lang="EN-US" style="font-size: 12pt; ">x1&lt;=x&lt;=x2</span><span style="font-size: 12pt; font-family: 宋体; ">且</span><span lang="EN-US" style="font-size: 12pt; ">y1&lt;=y&lt;=y2</span><span style="font-size: 12pt; font-family: 宋体; ">的士兵产生了</span><span lang="EN-US" style="font-size: 12pt; ">s</span><span style="font-size: 12pt; font-family: 宋体; ">的疲劳值。</span><span lang="EN-US" style="font-size: 12pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span lang="EN-US" style="font-size: 12pt; ">(1&lt;=x1&lt;=x2&lt;=n</span><span style="font-size: 12pt; font-family: 宋体; ">，</span><span lang="EN-US" style="font-size: 12pt; ">1&lt;=y1&lt;=y2&lt;=m</span><span style="font-size: 12pt; font-family: 宋体; ">，</span><span lang="EN-US" style="font-size: 12pt; ">0&lt;=s&lt;=1000)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span style="font-size: 12pt; font-family: 宋体; ">接下来</span><span lang="EN-US" style="font-size: 12pt; ">q</span><span style="font-size: 12pt; font-family: 宋体; ">行，每行</span><span lang="EN-US" style="font-size: 12pt; ">2</span><span style="font-size: 12pt; font-family: 宋体; ">个整数</span><span lang="EN-US" style="font-size: 12pt; ">x,y(x,y&lt;=10^9)</span><span style="font-size: 12pt; font-family: 宋体; ">，描述一个询问，询问是被加密的。一个询问的密码是上一个询问的答案</span><span lang="EN-US" style="font-size: 12pt; ">(</span><span style="font-size: 12pt; font-family: 宋体; ">记为</span><span lang="EN-US" style="font-size: 12pt; ">c)</span><span style="font-size: 12pt; font-family: 宋体; ">，第一个询问的密码是</span><span lang="EN-US" style="font-size: 12pt; ">0</span><span style="font-size: 12pt; font-family: 宋体; ">。询问参数的计算方式如下：</span><span lang="EN-US" style="font-size: 12pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span lang="EN-US" style="font-size: 12pt; ">x1=c % n+1,x2=(c+x) % n+1</span><span style="font-size: 12pt; font-family: 宋体; ">，如果</span><span lang="EN-US" style="font-size: 12pt; ">x1&gt;x2</span><span style="font-size: 12pt; font-family: 宋体; ">则交换</span><span lang="EN-US" style="font-size: 12pt; ">x1</span><span style="font-size: 12pt; font-family: 宋体; ">和</span><span lang="EN-US" style="font-size: 12pt; ">x2<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span lang="EN-US" style="font-size: 12pt; ">y1=c % m+1,y2=(c+y) % m +1</span><span style="font-size: 12pt; font-family: 宋体; ">，如果</span><span lang="EN-US" style="font-size: 12pt; ">y1&gt;y2</span><span style="font-size: 12pt; font-family: 宋体; ">则交换</span><span lang="EN-US" style="font-size: 12pt; ">y1</span><span style="font-size: 12pt; font-family: 宋体; ">和</span><span lang="EN-US" style="font-size: 12pt; ">y2<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span style="font-size: 12pt; font-family: 宋体; ">询问所有坐标</span><span lang="EN-US" style="font-size: 12pt; ">(x,y)</span><span style="font-size: 12pt; font-family: 宋体; ">满足</span><span lang="EN-US" style="font-size: 12pt; ">x1&lt;=x&lt;=x2</span><span style="font-size: 12pt; font-family: 宋体; ">且</span><span lang="EN-US" style="font-size: 12pt; ">y1&lt;=y&lt;=y2</span><span style="font-size: 12pt; font-family: 宋体; ">的士兵的疲劳值总和。</span><span lang="EN-US" style="font-size: 12pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 21pt; "><span style="font-size: 12pt; font-family: 宋体; ">保证答案</span><span lang="EN-US" style="font-size: 12pt; ">&lt;2^64</span><span style="font-size: 12pt; font-family: 宋体; ">。</span><span lang="EN-US" style="font-size: 12pt; "><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt; "><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><font face="宋体" size="3"><br />
</font></p>
<p class="MsoNormal"></p>
</div></p><hr/><h3>输出格式</h3><p><p></p>
<div></div>
<div>
<p class="MsoNormal" style="text-indent: 21pt; "><span style="font-size: 12pt; font-family: 宋体; ">对于每个询问，输出一行答案。</span><span lang="EN-US" style="font-size: 12pt; "><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size: 12pt; "><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"></p>
</div></p><hr/><h3>样例输入</h3><pre>
输入样例1

4 5 3 3

1 3 2 2 7

2 4 2 3 5

1 4 4 5 6

1 2

0 3

2 2
</pre><hr/><h3>样例输出</h3><pre>
输出样例1

24

12

46

 

第一次询问的是左上角坐标为(1,1),右下角坐标为(2,3)的这个矩形

第二次询问的是左上角坐标为(1,3),右下角坐标为(1,5)的这个矩形

第三次询问的是左上角坐标为(1,3)，右下角坐标为(3,5)这个矩形

 

 

 

 

输入样例2

5 5 5 5

1 1 1 3 242

1 4 4 5 83

3 5 3 3 221

2 2 1 3 254

5 5 2 2 105

0 1

0 4

2 1

1 3

0 1

 

输出样例2

484

0

992

442

304

 

 </pre><hr/><h3>提示</h3><p><p><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;
font-family:宋体;mso-ascii-font-family:&quot;Times New Roman&quot;;mso-hansi-font-family:
&quot;Times New Roman&quot;;mso-bidi-font-family:&quot;Times New Roman&quot;;mso-font-kerning:1.0pt;
mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">对于</span><span lang="EN-US" style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;;
mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;
mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">100%</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:
ZH-CN;mso-bidi-language:AR-SA">的数据</span><span lang="EN-US" style="font-size:
12.0pt;mso-bidi-font-size:10.0pt;font-family:&quot;Times New Roman&quot;;mso-fareast-font-family:
宋体;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;
mso-bidi-language:AR-SA"> n,m&lt;=10^8,k&lt;=40000,q&lt;=100000</span><span style="font-size:12.0pt;mso-bidi-font-size:10.0pt;font-family:宋体;mso-ascii-font-family:
&quot;Times New Roman&quot;;mso-hansi-font-family:&quot;Times New Roman&quot;;mso-bidi-font-family:
&quot;Times New Roman&quot;;mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:
ZH-CN;mso-bidi-language:AR-SA">；</span></p>
<p></p></p><hr/><h3>题目来源</h3><p>By Ryz</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2874" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2874" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>